home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_13_05 / ALLISON.ZIP / PERSON3.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-13  |  573 b   |  29 lines

  1. LISTING 22 - Adds the assignment operator and copy constructor to
  2. the Person class
  3. //person3.cpp
  4. #include <iostream.h>
  5. #include <string.h>
  6. #include <new.h>         // for placement new
  7. #include "person3.h"
  8.  
  9. Person::Person(const Person & p)
  10.   : birth(p.birth)
  11. {
  12.     last = clone(p.last);
  13.     first = clone(p.first);
  14.     ssn = clone(p.ssn);
  15. }
  16.  
  17. Person & Person::operator=(const Person & p)
  18. {
  19.     if (this != &p)
  20.     {
  21.         this->Person::~Person();
  22.         new (this) Person(p);
  23.     }
  24.     return *this;
  25. }
  26.  
  27. // (other functions as in Listing 20)
  28.  
  29.